import 'dart:ui';
import 'package:factoryside/api/api.dart';
import 'package:factoryside/bean/add_order_entity.dart';
import 'package:factoryside/bean/factory_brand_entity.dart';
import 'package:factoryside/bean/factory_prod_entity.dart';
import 'package:factoryside/bean/order_detail_entity.dart';
import 'package:factoryside/bean/prod_category_entity.dart';
import 'package:factoryside/bean/prod_model_entity.dart';
import 'package:factoryside/bean/prod_specifications_entity.dart';
import 'package:factoryside/generated/json/factory_brand_entity_helper.dart';
import 'package:factoryside/generated/json/factory_prod_entity_helper.dart';
import 'package:factoryside/generated/json/prod_category_entity_helper.dart';
import 'package:factoryside/generated/json/prod_model_entity_helper.dart';
import 'package:factoryside/generated/json/prod_specifications_entity_helper.dart';
import 'package:factoryside/home/page_next.dart';
import 'package:factoryside/utils/ColorsUtils.dart';
import 'package:factoryside/utils/request_util.dart';
import 'package:factoryside/utils/utils.dart';
import 'package:factoryside/widget/jh_login_textfield.dart';
import 'package:factoryside/widget/my_number_textInputFormatter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';


///修改产品

class ChangeProdPage extends StatefulWidget {
  OrderDetailEntity order;

  ChangeProdPage(this.order);

  @override
  State<StatefulWidget> createState() {
    return _ChangeProdState();
  }
}

class _ChangeProdState extends State<ChangeProdPage> with AutomaticKeepAliveClientMixin {
  var searchCon = TextEditingController();
  var searchOfCategoryCon = TextEditingController();
  var searchOfSpecificationsCon = TextEditingController();
  var searchOfBrandCon = TextEditingController();
  var searchOfModelCon = TextEditingController();
  var searchOfPartCon = TextEditingController();
  var categoryCon = TextEditingController();
  var specificationCon = TextEditingController();
  var brandCon = TextEditingController();
  var modelCon = TextEditingController();

  var numCon = TextEditingController();

  var timeCon = TextEditingController();
  var barcodeCon = TextEditingController();
  var prodExpressNoCon = TextEditingController();
  var expressNoCon = TextEditingController();
  var memoCon = TextEditingController();

  List<FactoryProdEntityIsSelected> prodList = []; //常用型号
  FactoryProdEntityIsSelected fpSelected;

  int subCategoryID;

  int specificationsID;

  int modelID;

  int brandID;

  OrderDetailOrderProductModel orderProductModel;


  @override
  void initState() {
    super.initState();
    orderProductModel = widget.order.orderProductModels[0];
    subCategoryID=orderProductModel.subCategoryID;
    specificationsID=orderProductModel.productTypeID;
    brandID=orderProductModel.brandID;
    modelID=orderProductModel.prodModelID;
    categoryCon.text=orderProductModel.subCategoryName;
    specificationCon.text=orderProductModel.productType;
    brandCon.text=orderProductModel.brandName;
    modelCon.text=orderProductModel.prodModelName;
    memoCon.text=orderProductModel.memo;
    searchCommonProd('');
  }

  void searchCommonProd(String keyword) {
    RequestUtil.post(Api.getFactoryProd, {'sreachName': keyword}).then((value) {
      List tempList = value['Data'];
      prodList.clear();
      tempList.forEach((element) {
        prodList.add(FactoryProdEntityIsSelected(
            factoryProdEntityFromJson(FactoryProdEntity(), element)));
      });
      setState(() {});
    });
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context); //必须实现 不然 在push过后页面会刷新
    // TODO: implement build
    var signs = [
      '保内安装',
      '待预约',
      '配件待审核',
      '配件审核通过',
      '催单',
      '费用待审核',
      '费用审核不通过',
      '超时未预约',
      '今日需上门',
      '超时未上门',
      '新留言'
    ];
    var colors = [
      '#2196F3',
      '#FD8387',
      '#5AFF15',
      '#FFFE1D',
      '#2DFFE9',
      '#C100FD',
      '#B4D1FB',
      '#FF67C5',
      '#E2FFBA',
      '#88FFD6',
      '#FDFF39',
    ];
    return Scaffold(
      appBar: AppBar(
        title: Text('修改产品'),
      ),
      body: Container(
        color: ColorsUtil.hexToColor('#EFEFEF'),
        child: Column(children: [
          Expanded(
            child: ListView(
              children: [
                Container(
                  color: Colors.white,
                  margin: EdgeInsets.symmetric(vertical: 10),
                  child: Column(
                    children: [
                      Container(
                        margin: EdgeInsets.all(10),
                        decoration: BoxDecoration(
                            color: Color.fromARGB(180, 240, 240, 240),
                            borderRadius: BorderRadius.all(Radius.circular(3))),
                        child: Row(
                          children: [
                            Expanded(
                                child: Container(
                                    padding:
                                        EdgeInsets.symmetric(horizontal: 10),
                                    child: TextField(
                                      controller: searchCon,
                                      onSubmitted: (keyword){
                                        searchCommonProd(keyword);
                                      },
                                      style: TextStyle(
                                          fontSize: 16, color: Colors.black),
                                      maxLines: 1,
//                                    keyboardType: TextInputType.text,
                                      decoration: InputDecoration(
                                        hintText: '搜索常用型号',
                                        counterText: '',
                                        disabledBorder: InputBorder.none,
                                        enabledBorder: InputBorder.none,
                                        focusedBorder: InputBorder.none,
                                      ),
                                    ))),
                            ElevatedButton(onPressed: () {
                              if (searchCon.text.isNotEmpty) {
                                searchCommonProd(searchCon.text);
                              } else {
                                showToast('内容不能为空');
                              }
                            }, child: Text('搜索')),
                          ],
                        ),
                      ),
                      Container(
                        padding: EdgeInsets.all(10),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text('常用：'),
                            Expanded(
                              child: prodList.length>0?Wrap(
                                spacing: 5,
                                runSpacing: 5,
                                children: prodList
                                    .map((element) => InkWell(
                                  child: Container(
                                    padding: EdgeInsets.symmetric(
                                        vertical: 8, horizontal: 10),
                                    decoration: BoxDecoration(
                                        color: ColorsUtil.hexToColor(
                                            element.isSelected?'#FD8387':'#ffffff'),
                                        border: Border.all(
                                            width: 0.2,
                                            color: Colors.grey),
                                        borderRadius: BorderRadius.all(
                                            Radius.circular(2))),
                                    child: Text(
                                      '${element.prod.brandName}-${element.prod.prodModel}',
                                      style: TextStyle(
                                          fontSize: 16,
                                          color: element.isSelected?Colors.white:Colors.black),
                                      textAlign: TextAlign.center,
                                    ),
                                  ),
                                  onTap: (){
                                    fpSelected=element;

                                    subCategoryID=fpSelected.prod.subCategoryID;
                                    specificationsID=fpSelected.prod.productTypeID;
                                    brandID=fpSelected.prod.brandID;
                                    modelID=fpSelected.prod.prodModelID;

                                    categoryCon.text=fpSelected.prod.subCategoryName;
                                    specificationCon.text=fpSelected.prod.productTypeName;
                                    brandCon.text=fpSelected.prod.brandName;
                                    modelCon.text=fpSelected.prod.prodModel;

                                    prodList.forEach((temp) {
                                      if(element.prod.id==temp.prod.id){
                                        temp.isSelected=true;
                                      }else{
                                        temp.isSelected=false;
                                      }
                                    });
                                    setState(() {

                                    });
                                  },
                                ))
                                    .toList(),
                              ):Text('没有任何产品',style: TextStyle(color: Colors.grey),),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  child: Column(
                    children: [
                      GestureDetector(
                        child: Container(
                          color: Colors.white,
                          padding: EdgeInsets.all(10),
                          child: Row(
                            children: [
                              Text('*产品类别：'),
                              SizedBox(
                                width: 10,
                              ),
                              Expanded(
                                  child: JhLoginTextField(
                                controller: categoryCon,
//                                  text: districtName != null
//                                      ? '$provinceName$cityName$areaName$districtName'
//                                      : '',
                                hintText: '请选择产品类别',
                                border: InputBorder.none,
                                isShowDeleteBtn: false,
                                isDense: true,
                                enable: false,
                              )),
                              Icon(
                                Icons.chevron_right,
                                color: Colors.grey,
                              )
                            ],
                          ),
                        ),
                        onTap: () {
                          showPopOfCate();
                        },
                      ),
                      Divider(
                        height: 1,
                      ),
                      GestureDetector(
                        child: Container(
                          color: Colors.white,
                          padding: EdgeInsets.all(10),
                          child: Row(
                            children: [
                              Text('*产品规格：'),
                              SizedBox(
                                width: 10,
                              ),
                              Expanded(
                                  child: JhLoginTextField(
                                controller: specificationCon,
//                                  text: districtName != null
//                                      ? '$provinceName$cityName$areaName$districtName'
//                                      : '',
                                hintText: '请选择产品规格',
                                border: InputBorder.none,
                                isShowDeleteBtn: false,
                                isDense: true,
                                enable: false,
                              )),
                              Icon(
                                Icons.chevron_right,
                                color: Colors.grey,
                              )
                            ],
                          ),
                        ),
                        onTap: () {
                          showPopOfSpecification();
                        },
                      ),
                      Divider(
                        height: 1,
                      ),
                      GestureDetector(
                        child: Container(
                          color: Colors.white,
                          padding: EdgeInsets.all(10),
                          child: Row(
                            children: [
                              Text('*产品品牌：'),
                              SizedBox(
                                width: 10,
                              ),
                              Expanded(
                                  child: JhLoginTextField(
                                controller: brandCon,
//                                  text: districtName != null
//                                      ? '$provinceName$cityName$areaName$districtName'
//                                      : '',
                                hintText: '请选择产品品牌',
                                border: InputBorder.none,
                                isShowDeleteBtn: false,
                                isDense: true,
                                enable: false,
                              )),
                              Icon(
                                Icons.chevron_right,
                                color: Colors.grey,
                              )
                            ],
                          ),
                        ),
                        onTap: () {
                          showPopOfBrand();
                        },
                      ),
                      Divider(
                        height: 1,
                      ),
                      GestureDetector(
                        child: Container(
                          color: Colors.white,
                          padding: EdgeInsets.all(10),
                          child: Row(
                            children: [
                              Text('*产品型号：'),
                              SizedBox(
                                width: 10,
                              ),
                              Expanded(
                                  child: JhLoginTextField(
                                controller: modelCon,
//                                  text: districtName != null
//                                      ? '$provinceName$cityName$areaName$districtName'
//                                      : '',
                                hintText: '请选择产品型号',
                                border: InputBorder.none,
                                isShowDeleteBtn: false,
                                isDense: true,
                                enable: false,
                              )),
                              Icon(
                                Icons.chevron_right,
                                color: Colors.grey,
                              )
                            ],
                          ),
                        ),
                        onTap: () {
                          showPopOfModel();
                        },
                      ),

                    ],
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: 10),
                  padding: EdgeInsets.all(10),
                  color: Colors.white,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('*服务要求：'),
                      SizedBox(
                        width: 10,
                      ),
                      Container(
                          padding:
                              EdgeInsets.only(bottom: 5, left: 10, right: 10),
                          width: double.infinity,
                          decoration: BoxDecoration(
//                              color: Color.fromARGB(180, 240, 240, 240),
//                    border: Border.all(
//                        width: 0.2, color: Colors.grey),
                              borderRadius:
                                  BorderRadius.all(Radius.circular(3))),
                          child: TextField(
                            controller: memoCon,
                            style: TextStyle(fontSize: 16, color: Colors.black),
                            maxLines: 4,
//                                    keyboardType: TextInputType.text,
                            decoration: InputDecoration(
                              hintText: '请填写服务要求',
                              counterText: '',
                              disabledBorder: InputBorder.none,
                              enabledBorder: InputBorder.none,
                              focusedBorder: InputBorder.none,
                            ),
                          )),
                    ],
                  ),
                ),
              ],
            ),
          ),
          Container(
              color: Colors.white,
              padding: EdgeInsets.fromLTRB(0, 5, 20, 5),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  ElevatedButton(
                      onPressed: () {
                        if(subCategoryID==null){
                          showToast('请选择类别');
                          return;
                        }
                        if(specificationsID==null){
                          showToast('请选择规格');
                          return;
                        }
                        if(brandID==null){
                          showToast('请选择品牌');
                          return;
                        }
                        if(modelID==null){
                          showToast('请选择型号');
                          return;
                        }
                        if(memoCon.text.isEmpty){
                          showToast('请填写服务要求');
                          return;
                        }
                        RequestUtil.post(Api.updateOrderProd, {
                          'orderId':widget.order.orderID,
                          'subCategoryID':subCategoryID,
                          'specifications':specificationsID,
                          'factoryBrandName':brandID,
                          'prodModel':modelID,
                          'Memo':memoCon.text,
                          'Id':orderProductModel.orderProdcutID,
                        }).then((value) {
                          if(value['Data']['code']==0){
                            Navigator.pop(context,true);
                          }else{
                            showToast(value['Data']['msg']);
                          }
                        });
                      },
                      child: Text('提交')),
                ],
              )),
        ]),
      ),
    );
  }
  ///选择型号
  void showPopOfModel() {
    List<ProdModelEntity> prodModelList=[];
    if(specificationsID==null){
      showToast('请先选择规格');
      return;
    }
    RequestUtil.post(Api.getProdModel, {'specificationsID':specificationsID}).then((value) {
      List tempList=value['Data'];
      tempList.forEach((element) {
        prodModelList.add(prodModelEntityFromJson(ProdModelEntity(), element));
      });
      if (prodModelList.length>0) {
        showModalBottomSheet(
            context: context,
            isScrollControlled: true,
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(10), topRight: Radius.circular(10))),
            builder: (context) {
              return Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Stack(
                    children: [
                      Align(
                        alignment: Alignment.center,
                        child: Padding(
                          padding: const EdgeInsets.symmetric(vertical: 14),
                          child: Text(
                            '产品型号',
                            style: TextStyle(fontSize: 18),
                          ),
                        ),
                      ),
                      Align(
                        alignment: Alignment.topRight,
                        child: Container(
                          margin: EdgeInsets.only(right: 10),
                          child: TextButton(
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                              child: Text('取消')),
                        ),
                      ),
                    ],
                  ),
//              Container(
//                margin: EdgeInsets.all(10),
//                decoration: BoxDecoration(
//                    color: Color.fromARGB(180, 240, 240, 240),
//                    borderRadius: BorderRadius.all(Radius.circular(3))),
//                child: Row(
//                  children: [
//                    Expanded(
//                        child: Container(
//                            padding: EdgeInsets.symmetric(horizontal: 10),
//                            child: TextField(
//                              controller: searchOfModelCon,
//                              style:
//                                  TextStyle(fontSize: 16, color: Colors.black),
//                              maxLines: 1,
////                                    keyboardType: TextInputType.text,
//                              decoration: InputDecoration(
//                                hintText: '搜索型号',
//                                counterText: '',
//                                disabledBorder: InputBorder.none,
//                                enabledBorder: InputBorder.none,
//                                focusedBorder: InputBorder.none,
//                              ),
//                            ))),
//                    ElevatedButton(onPressed: () {}, child: Text('搜索')),
//                  ],
//                ),
//              ),
//              Container(
//                margin: EdgeInsets.symmetric(horizontal: 10),
//                child: ElevatedButton(
//                    onPressed: () {
//                      showToast('待开发...');
//                    },
//                    child: Container(
//                        padding: EdgeInsets.symmetric(vertical: 15),
//                        child: Row(
//                      mainAxisAlignment: MainAxisAlignment.center,
//                      children: [
//                        Text('添加新型号'),
//                      ],
//                    ))),
//              ),
                  Container(
                    height: MediaQuery.of(context).size.height * 0.6,
                    child: ListView.separated(
                      itemCount: prodModelList.length,
                      itemBuilder: (context, index) => ListTile(
                          title: Text(prodModelList[index].modelName),
                          onTap: (){
                            setState(() {
                              modelCon.text=prodModelList[index].modelName;
                              modelID=prodModelList[index].id;
                              Navigator.pop(context);
                            });
                          }
                      ),
                      separatorBuilder: (context, index) => Divider(),
                    ),
                  )
                ],
              );
            });
      } else {
        showToast('暂未配置型号，请在电脑端配置');
      }
    });

  }

  ///选择类别
  void showPopOfCate() {
    List<ProdCategoryEntity> cateList=[];
    RequestUtil.post(Api.getProdCategory, {}).then((value) {
      List tempList=value['Data'];
      tempList.forEach((element) {
        cateList.add(prodCategoryEntityFromJson(ProdCategoryEntity(), element));
      });
      if (cateList.length>0) {
        showModalBottomSheet(
                  context: context,
                  isScrollControlled: true,
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(10), topRight: Radius.circular(10))),
                  builder: (context) {
                    return Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Stack(
                          children: [
                            Align(
                              alignment: Alignment.center,
                              child: Padding(
                                padding: const EdgeInsets.symmetric(vertical: 14),
                                child: Text(
                                  '产品类别',
                                  style: TextStyle(fontSize: 18),
                                ),
                              ),
                            ),
                            Align(
                              alignment: Alignment.topRight,
                              child: Container(
                                margin: EdgeInsets.only(right: 10),
                                child: TextButton(
                                    onPressed: () {
                                      Navigator.of(context).pop();
                                    },
                                    child: Text('取消')),
                              ),
                            ),
                          ],
                        ),
        //              Container(
        //                margin: EdgeInsets.all(10),
        //                decoration: BoxDecoration(
        //                    color: Color.fromARGB(180, 240, 240, 240),
        //                    borderRadius: BorderRadius.all(Radius.circular(3))),
        //                child: Row(
        //                  children: [
        //                    Expanded(
        //                        child: Container(
        //                            padding: EdgeInsets.symmetric(horizontal: 10),
        //                            child: TextField(
        //                              controller: searchOfCategoryCon,
        //                              style:
        //                                  TextStyle(fontSize: 16, color: Colors.black),
        //                              maxLines: 1,
        ////                                    keyboardType: TextInputType.text,
        //                              decoration: InputDecoration(
        //                                hintText: '搜索类别',
        //                                counterText: '',
        //                                disabledBorder: InputBorder.none,
        //                                enabledBorder: InputBorder.none,
        //                                focusedBorder: InputBorder.none,
        //                              ),
        //                            ))),
        //                    ElevatedButton(onPressed: () {}, child: Text('搜索')),
        //                  ],
        //                ),
        //              ),
        //              Container(
        //                margin: EdgeInsets.symmetric(horizontal: 10),
        //                child: ElevatedButton(
        //                    onPressed: () {},
        //                    child: Container(
        //                        child: Row(
        //                      mainAxisAlignment: MainAxisAlignment.center,
        //                      children: [
        //                        Text('添加新类别'),
        //                      ],
        //                    ))),
        //              ),
                        Container(
                          height: MediaQuery.of(context).size.height * 0.6,
                          child: ListView.separated(
                            itemCount: cateList.length,
                            itemBuilder: (context, index) => ListTile(
                              title: Text(cateList[index].fCategoryName),
                              onTap: (){
                                setState(() {
                                  categoryCon.text=cateList[index].fCategoryName;
                                  subCategoryID=cateList[index].specificationsID;
                                  specificationsID=null;
                                  specificationCon.text='';
                                  modelID=null;
                                  modelCon.text='';
                                  Navigator.pop(context);
                                });
                              },
                            ),
                            separatorBuilder: (context, index) => Divider(),
                          ),
                        )
                      ],
                    );
                  });
      } else {
        showToast('暂未配置类别，请在电脑端配置');
      }
    });

  }

  ///选择规格
  void showPopOfSpecification() {
    List<ProdSpecificationsEntity> specificationsList=[];
    if(subCategoryID==null){
      showToast('请先选择类别');
      return;
    }
    RequestUtil.post(Api.getProdSpecifications, {'subCategoryID':subCategoryID}).then((value) {
      List tempList=value['Data'];
      tempList.forEach((element) {
        specificationsList.add(prodSpecificationsEntityFromJson(ProdSpecificationsEntity(), element));
      });
      if (specificationsList.length>0) {
        showModalBottomSheet(
            context: context,
            isScrollControlled: true,
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(10), topRight: Radius.circular(10))),
            builder: (context) {
              return Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Stack(
                    children: [
                      Align(
                        alignment: Alignment.center,
                        child: Padding(
                          padding: const EdgeInsets.symmetric(vertical: 14),
                          child: Text(
                            '产品规格',
                            style: TextStyle(fontSize: 18),
                          ),
                        ),
                      ),
                      Align(
                        alignment: Alignment.topRight,
                        child: Container(
                          margin: EdgeInsets.only(right: 10),
                          child: TextButton(
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                              child: Text('取消')),
                        ),
                      ),
                    ],
                  ),
//              Container(
//                margin: EdgeInsets.all(10),
//                decoration: BoxDecoration(
//                    color: Color.fromARGB(180, 240, 240, 240),
//                    borderRadius: BorderRadius.all(Radius.circular(3))),
//                child: Row(
//                  children: [
//                    Expanded(
//                        child: Container(
//                            padding: EdgeInsets.symmetric(horizontal: 10),
//                            child: TextField(
//                              controller: searchOfSpecificationsCon,
//                              style:
//                                  TextStyle(fontSize: 16, color: Colors.black),
//                              maxLines: 1,
////                                    keyboardType: TextInputType.text,
//                              decoration: InputDecoration(
//                                hintText: '搜索规格',
//                                counterText: '',
//                                disabledBorder: InputBorder.none,
//                                enabledBorder: InputBorder.none,
//                                focusedBorder: InputBorder.none,
//                              ),
//                            ))),
//                    ElevatedButton(onPressed: () {}, child: Text('搜索')),
//                  ],
//                ),
//              ),
//              Container(
//                margin: EdgeInsets.symmetric(horizontal: 10),
//                child: ElevatedButton(
//                    onPressed: () {},
//                    child: Container(
//                        child: Row(
//                      mainAxisAlignment: MainAxisAlignment.center,
//                      children: [
//                        Text('添加规格'),
//                      ],
//                    ))),
//              ),
                  Container(
                    height: MediaQuery.of(context).size.height * 0.6,
                    child: ListView.separated(
                      itemCount: specificationsList.length,
                      itemBuilder: (context, index) => ListTile(
                        title: Text(specificationsList[index].fCategoryName),
                        onTap: (){
                          setState(() {
                            specificationCon.text=specificationsList[index].fCategoryName;
                            specificationsID=specificationsList[index].specificationsID;
                            modelID=null;
                            modelCon.text='';
                            Navigator.pop(context);
                          });
                        },
                      ),
                      separatorBuilder: (context, index) => Divider(),
                    ),
                  )
                ],
              );
            });
      } else {
        showToast('暂未配置规格，请在电脑端配置');
      }
    });

  }

  ///选择品牌
  void showPopOfBrand() {
    List<FactoryBrandEntity> brandList=[];
    RequestUtil.post(Api.getFactoryBrand, {}).then((value) {
      List tempList=value['Data'];
      tempList.forEach((element) {
        brandList.add(factoryBrandEntityFromJson(FactoryBrandEntity(), element));
      });
      if (brandList.length>0) {
        showModalBottomSheet(
            context: context,
            isScrollControlled: true,
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(10), topRight: Radius.circular(10))),
            builder: (context) {
              return Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Stack(
                    children: [
                      Align(
                        alignment: Alignment.center,
                        child: Padding(
                          padding: const EdgeInsets.symmetric(vertical: 14),
                          child: Text(
                            '产品品牌',
                            style: TextStyle(fontSize: 18),
                          ),
                        ),
                      ),
                      Align(
                        alignment: Alignment.topRight,
                        child: Container(
                          margin: EdgeInsets.only(right: 10),
                          child: TextButton(
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                              child: Text('取消')),
                        ),
                      ),
                    ],
                  ),
//              Container(
//                margin: EdgeInsets.all(10),
//                decoration: BoxDecoration(
//                    color: Color.fromARGB(180, 240, 240, 240),
//                    borderRadius: BorderRadius.all(Radius.circular(3))),
//                child: Row(
//                  children: [
//                    Expanded(
//                        child: Container(
//                            padding: EdgeInsets.symmetric(horizontal: 10),
//                            child: TextField(
//                              controller: searchOfBrandCon,
//                              style:
//                                  TextStyle(fontSize: 16, color: Colors.black),
//                              maxLines: 1,
////                                    keyboardType: TextInputType.text,
//                              decoration: InputDecoration(
//                                hintText: '搜索品牌',
//                                counterText: '',
//                                disabledBorder: InputBorder.none,
//                                enabledBorder: InputBorder.none,
//                                focusedBorder: InputBorder.none,
//                              ),
//                            ))),
//                    ElevatedButton(onPressed: () {}, child: Text('搜索')),
//                  ],
//                ),
//              ),
//              Container(
//                margin: EdgeInsets.symmetric(horizontal: 10),
//                child: ElevatedButton(
//                    onPressed: () {
//                      showToast('待开发...');
//                    },
//                    child: Container(
//                        padding: EdgeInsets.symmetric(vertical: 15),
//                        child: Row(
//                      mainAxisAlignment: MainAxisAlignment.center,
//                      children: [
//                        Text('添加新品牌'),
//                      ],
//                    ))),
//              ),
                  Container(
                    height: MediaQuery.of(context).size.height * 0.6,
                    child: ListView.separated(
                      itemCount: brandList.length,
                      itemBuilder: (context, index) => ListTile(
                          title: Text(brandList[index].fBrandName),
                          onTap: (){
                            setState(() {
                              brandCon.text=brandList[index].fBrandName;
                              brandID=brandList[index].fBrandID;
                              Navigator.pop(context);
                            });
                          }
                      ),
                      separatorBuilder: (context, index) => Divider(),
                    ),
                  )
                ],
              );
            });
      } else {
        showToast('暂未配置品牌，请在电脑端配置');
      }
    });

  }
}
